package com.sbio.udiapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.sbio.udiapp.R;
import com.sbio.udiapp.common.bean.ExpressPriceResult;

import java.util.List;

public class ComparePriceListViewAdapter extends BaseAdapter {

    private Context context;


    private List<ExpressPriceResult> datas;

    public ComparePriceListViewAdapter(Context context, List<ExpressPriceResult> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_compare_price_listview, parent, false);
            viewHolder.expressCompany = convertView.findViewById(R.id.expressCompany);
            viewHolder.serviceMode = convertView.findViewById(R.id.serviceMode);
            viewHolder.arrivalTime = convertView.findViewById(R.id.arrivalTime);
            viewHolder.price = convertView.findViewById(R.id.price);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ExpressPriceResult expressPriceResult = datas.get(position);
        viewHolder.expressCompany.setText(expressPriceResult.getExpressCompany());
        viewHolder.serviceMode.setText(expressPriceResult.getServiceMode());
        viewHolder.arrivalTime.setText(expressPriceResult.getArrivalTime());
        viewHolder.price.setText(expressPriceResult.getPrice());
        return convertView;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    class ViewHolder{
        TextView expressCompany;
        TextView serviceMode;
        TextView arrivalTime;
        TextView price;


        public ViewHolder() {

        }
    }
}
